import { RouteRecordRedirectOption } from 'vue-router'

import { checkKey } from '@/directives/auth'

// 重定向第一级有权限的子菜单
export const redirectPath: RouteRecordRedirectOption = to => {
  const routes = to.matched.at(-1)?.children || []
  console.log(routes, 'routes')
  const hasAuthFirstItem = routes.find(route => checkKey(route.meta?.auth as string)) || {
    path: '/'
  }
  console.log(hasAuthFirstItem.path, 'hasAuthFirstItem.path')

  return hasAuthFirstItem.path
}
